package cn.uin.domain.auth.service;

import cn.uin.domain.auth.adapter.port.IAuthNotificationPort;
import cn.uin.domain.auth.adapter.repository.IAuthRepository;
import cn.uin.domain.auth.model.entity.HomeUserDetailEntity;
import cn.uin.domain.auth.model.entity.HomeUserEntity;
import cn.uin.domain.auth.model.entity.HomeUserRegisterEntity;
import cn.uin.domain.auth.model.entity.SendEmailEntity;
import cn.uin.domain.auth.model.valobj.RegisterTypeEnum;
import cn.uin.domain.auth.service.IHomeUserService;
import cn.uin.domain.auth.service.user.register.IRegisterStrategyService;
import cn.uin.domain.auth.service.user.register.factory.RegisterStrategyFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName HomeUserService
 * @Description:类描述
 * @Author: Administrator
 * @CreateDate: 2025/10/22 10:02
 * @Version: 1.0
 */
@Slf4j
@Service
public class HomeUserService implements IHomeUserService {

	@Resource
	private IAuthNotificationPort iAuthNotificationPort;

	@Resource
	private IAuthRepository iAuthRepository;

	@Override
	public HomeUserEntity register(HomeUserRegisterEntity homeUserRegisterEntity) {
		IRegisterStrategyService strategyService = RegisterStrategyFactory.get(RegisterTypeEnum.get(homeUserRegisterEntity.getType()).getInfo());
		return strategyService.register(homeUserRegisterEntity);
	}

	@Override
	public boolean sendEmailCode(Integer type, String email) {
		return iAuthNotificationPort.sendEmailCode(type, email);
	}

	@Override
	public boolean sendPhoneCode(Integer type, String phone) {
		return iAuthNotificationPort.sendPhoneCode(type, phone);
	}

	@Override
	public boolean editUserDetail(HomeUserDetailEntity homeUserDetailEntity) {
		try {
			iAuthRepository.editUserDetail(homeUserDetailEntity);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
}
